<template>
  <div class="region">
    <div class="content">
      <div class="left">
        地区:
      </div>
      <ul>
        <li
          :class="{active : regionFlag === ''}"
          @click="regionChange('')"
        >全部</li>
        <li
          v-for="(item, index) in regionList"
          :key="item.value"
          :class="{active : regionFlag === item.value}"
          @click="regionChange(item.value)"
        >{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import {defineEmits, onMounted, ref} from "vue";
import {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type";
import { reqHospitalLevelAndRegion } from "@/api/home";

let regionList = ref<HospitalLevelAndRegionArr>([])

let regionFlag = ref<string>('')

onMounted(() => {
  getHospitalRegion()
})

const getHospitalRegion = async () => {
  const result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('Beijin')
  if (result.code === 200) {
    regionList.value = result.data
  }
}

const regionChange = (value: string) => {
  regionFlag.value = value
  $emit('getRegion', value)
}

let $emit = defineEmits(['getRegion'])
</script>

<script lang="ts">
export default {
  name: 'Level'
}
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 10px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 44px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
        &:hover {
          color: #55a6fe;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
